package com.chb.microservice.provider.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;

import com.google.common.base.Predicates;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket testApi() {
		return new Docket(DocumentationType.SWAGGER_2).groupName("test").genericModelSubstitutes(DeferredResult.class)
				.useDefaultResponseMessages(false).forCodeGeneration(true).pathMapping("/")// base，最终调用接口后会和paths拼接在一起
				.select()
				// .paths(or(regex("/api/.*")))//过滤的接口
				.build().apiInfo(testApiInfo());
	}

	private ApiInfo testApiInfo() {
		ApiInfo apiInfo = new ApiInfo("重庆车保汇", // 大标题
				"feign", // 小标题
				"0.1", // 版本
				"NO terms of service", new Contact("后台", "swagger-ui.html", "598964985@qq.com"), // 作者
				"应用许可", // 链接显示文字
				"12333333"// 网站链接
		);
		return apiInfo;
	}

	@Bean
	public Docket demoApi() {
		return new Docket(DocumentationType.SWAGGER_2)// <3>
				.select()// <4>
				.apis(RequestHandlerSelectors.any())// <5>
				.paths(Predicates.not(PathSelectors.regex("/error.*")))// <6>
				.apis(RequestHandlerSelectors.basePackage("com.chb.microservice.provider.controller")).build()
				.apiInfo(testApiInfo());
	}
}
